package com.hd.assistant.biz.manager.ordermining;

import java.util.Date;
import java.util.List;

import com.hd.assistant.biz.manager.exception.ManagerException;
import com.hd.assistant.dal.dao.query.ordermining.ItemCostQuery;
import com.hd.assistant.dal.dao.query.ordermining.TcOrderQuery;
import com.hd.assistant.dal.dataobject.User;
import com.hd.assistant.dal.dataobject.ordermining.ItemCost;
import com.hd.assistant.dal.dataobject.ordermining.NotifyMessage;
import com.hd.assistant.dal.dataobject.ordermining.Reports;
import com.hd.assistant.dal.dataobject.ordermining.TcOrder;
import com.taobao.api.domain.Task;
import com.taobao.api.domain.Trade;

public interface OrderMiningManager {
	/**
	 * dump卖家的售卖中的宝贝到数据库
	 * 支持全量增量  
	 * endModify 不填的话 默认、now
	 * startModify endModify 两者都不填默认所有
	 * dump完以后会更新到user相关字段
	 * @param uid  数据库中用户对应的key
	 * @param appkey
	 * @param secret
	 * @param sessionKey
	 * @param startModify
	 * @param endModify
	 * @throws ManagerException
	 */
	int dumpSellerItemsToDB(User user,String appkey,String secret,String sessionKey,Date startModify,Date endModify) throws ManagerException;
	
	int dumpSellerInventoryItemsToDB(User user,String appkey,String secret,String sessionKey,Date startModify,Date endModify) throws ManagerException;
	
	ItemCostQuery getItemsByQuery(ItemCostQuery query)throws ManagerException;
	
	int updateCost(String itemId,double cost)throws ManagerException;
	
	/**
	 * 更新成本 名字取的不好
	 * @param update
	 * @return
	 * @throws ManagerException
	 */
	int update(ItemCost update)throws ManagerException;
	ItemCost getItemCostByItemId(String itemId)throws ManagerException;
	
	TcOrder getTcOrderByTid(Long tid)throws ManagerException;
	TcOrderQuery getTcOrdersByQuery(TcOrderQuery query)throws ManagerException;
	/**
	 * 批量更新成本 
	 * @param userId
	 * @param itemIds
	 * @param ratio
	 * @return
	 * @throws ManagerException
	 */
	int batchUpdateCost(long userId,String[] itemIds,double ratio)throws ManagerException;
	
	/**
	 * 加载并存储sku成本
	 * @param appkey
	 * @param secret
	 * @param sessionKey
	 * @param itemId
	 * @return
	 * @throws ManagerException
	 */
	public ItemCost loadAndStoreSkuInfo(String appkey,String secret,String sessionKey,String itemId)throws ManagerException;
	
	/**
	 * 计算利润信息 适合于新插入的订单  利润信息在trade里设置好了
	 * @param trade
	 * @return
	 * @throws ManagerException
	 */
	public boolean calOrderProfit(TcOrder trade)throws ManagerException;
	
	/**
	 * 计算利润信息 适合于数据库中已经有的记录的操作 
	 * 返回TcOrder 需要update的字段
	 * @param trade
	 * @return
	 * @throws ManagerException
	 */
	public TcOrder calOrderProfitAndReturnUpdate(TcOrder trade)throws ManagerException;
	
	/**
	 * 默认取用户最近的x条交易记录,默认为100
	 * @param user
	 * @param appkey
	 * @param secret
	 * @param sessionKey
	 * @param limit
	 * @return
	 */
	public int defaultDumpTradesToDB (User user,String appkey,String secret,String sessionKey,Long limit)throws ManagerException;
	
	/**
	 * 远程获取一条交易信息
	 * @param appkey
	 * @param secret
	 * @param sessionKey
	 * @param tid
	 * @return
	 * @throws ManagerException
	 */
	public Trade getOrderAppTradeInfoByTid(Long tid,Long userId)throws ManagerException;
	
	/**
	 * 增量导入今天的订单
	 * @param user
	 * @param appkey
	 * @param secret
	 * @param sessionKey
	 * @return
	 * @throws ManagerException
	 */
	public int dumpTodayTradesToDB(User user,String appkey,String secret,String sessionKey)throws ManagerException;
	
	public boolean reCalProfit(Long tid)throws ManagerException;
	
	/**
	 * 异步导入近3个月来的所有订单   转交消息池处理
	 * 包含两个阶段 1 发异步任务  同步到昨天为止的所有数据  接下来等待接收完成消息 等待异步处理
	 * step2 手工调用增量接口获取当日的数据
	 * @param user
	 * @param appkey
	 * @param secret
	 * @param sessionKey
	 * @return
	 * @throws ManagerException
	 */
	public int dumpNearlyTradesToDB(User user,String appkey,String secret,String sessionKey)throws ManagerException;
	
	public int calProfitOfAllDbNoprofitTcOrders(User user,Date endTimeStart);
	
	
	public void insertNotifyMessage(NotifyMessage message)throws ManagerException;
	
	public void convertTrade(Trade t,TcOrder trade, Long userId);
	
	public Task getTaskInfoByTaskId(Long taskId)throws ManagerException;
	
	public int update(TcOrder order)throws ManagerException;
	
	public List<Reports> getReportsByUserId(Long userId,Integer typr,String dateFrom,String dateTo)throws ManagerException;
	
	public List<Reports> getBuyerReportsByUserId(Long userId,Integer tradeFrom)throws ManagerException;
}
